<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/8/27 0027
  Time: 20:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
  <base href="<%=basePath%>">
  <meta charset="utf-8"/>
  <title></title>
  <link rel="stylesheet" type="text/css" href="easyui-1.3.6/themes/default/easyui.css">
  <link rel="stylesheet" type="text/css" href="easyui-1.3.6/themes/icon.css">
  <link rel="stylesheet" type="text/css" href="easyui-1.3.6/demo/demo.css">
  <script type="text/javascript" src="easyui-1.3.6/jquery.min.js"></script>
  <script type="text/javascript" src="easyui-1.3.6/jquery.easyui.min.js"></script>

</head>
<body>
<div class="row">
  <div class="col-md-12">
    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
    <h3 class="page-title" id="index-page-title" style="font: normal 30px/0.8em '微软雅黑'">孜点教科</h3>
    <ul class="page-breadcrumb breadcrumb">
      <%--<li>
        &lt;%&ndash;<i class="fa fa-home"></i>
        首页
        <i class="fa fa-angle-right"></i>&ndash;%&gt;
      </li>--%>
      <li>
        <%--<a href="javascript:;">--%>
        活动管理
        <%--</a>--%>
        <i class="fa fa-angle-right"></i>
      </li>
      <li>
        <%--<a href="javascript:;">--%>
        查看活动
        <%--</a>--%>
      </li>
    </ul>
    <!-- END PAGE TITLE & BREADCRUMB-->
  </div>
</div>

<input class="easyui-searchbox" data-options="prompt:'请输入活动的标题查询',searcher:doSearch" style="width:450px;height: 48px;background: transparent;border:none;"">

<div style="margin:20px 0;"></div>
<div id="test" class="easyui-dialog" data-options="closed:true,modal:true,title:'审核当前所选择的活动'" style="width: 400px;">
  <div style="width:368px;height:160px;" >
     <a href="javascript:void(0)" class="easyui-linkbutton" onclick="addActivity()" style="display:inline-block;width:120px;height:30px;margin:65px 0px 0px 63px;line-height:30px;float: left;">通过</a>
     <a href="javascript:void(0)" class="easyui-linkbutton" onclick="delActivity()" style="display:inline-block;width:120px;height:30px;margin:65px 0px 0px 20px;line-height:30px;float:left;">不通过</a>
  </div>
</div>
<table id="dg" title="活动信息表" style="width:auto;height:auto" data-options="
				rownumbers:true,
				singleSelect:true,
				autoRowHeight:false,
				pagination:true,
				pageSize:10
				">
  <thead>
  <tr>
    <th field="activityId" width="50">活动编号</th>
    <th field="activityTitle" width="200">活动标题</th>
    <th field="activityCollege" width="200">活动发布方</th>
    <th field="activityLocation" width="200">活动地点</th>
    <th field="activityTime" width="200">活动时间</th>
    <th field="activityType" width="100">活动类型</th>
    <th field="functionAttendance" width="100">活动参加人数</th>
  </tr>
  </thead>
</table>

<script>
  var i = 1;
  function pagerFilter(data){
    if(i==1&&data[0]!=null){
      var to = data[0].total;
      var wh = data[0].wh;
    }else if(i==2&&data!=null){
      var to = data.total;
      var wh = data.wh;
    }else{
      var to = 0;
      var wh = "";
    }
    if (typeof to== 'number' && typeof data.splice == 'function'){	// is array
      data = {
        total:to,
        rows: data,
        wh:wh
      }
      i=2;
    }
    var dg = $(this);
    var opts = dg.datagrid('options');
    var pager = dg.datagrid('getPager');
    pager.pagination({
      onSelectPage:function(pageNum, pageSize){
        opts.pageNumber = pageNum;
        opts.pageSize = pageSize;
        pager.pagination('refresh',{
          pageNumber:pageNum,
          pageSize:pageSize
        });
        var start = (opts.pageNumber-1)*parseInt(opts.pageSize);
//    var end = start + parseInt(opts.pageSize);
        data.rows = (getData(start,parseInt(opts.pageSize),wh));
        dg.datagrid('loadData',data);
      }
    });
    return data;
  }

  $(function(){
    $('#dg').datagrid({
      toolbar:[
        {
        text:'审核选中的活动',
        iconCls:'icon-remove',
        handler:function(){
          $('#test').window('open');
        }
      }
      ]})

    $('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData', getData(0,10,""));
  });
  function delActivity(){
    var row = $('#dg').datagrid('getSelected');
    if (delData(row.activityId)==200){
      var index = $('#dg').datagrid('getRowIndex', row);
      $('#test').window('close');
      $('#dg').datagrid('deleteRow', index);
    }
  }
  function delData(s){
    var code1 = 0;
    $.ajax({
      method : 'GET',
      url : 'rest/page/activityM/del?manageId=${user.teacherid}&activityId='+s+'',
      async : false,
      dataType : 'json',
      success : function(code) {
        code1 = code.code
        if(code.code == 200){
          $.messager.show({title:'操作提示',msg:code.message+"请点击表单下刷新按钮刷新显示",showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
        }else{
          $.messager.show({title:'操作提示',msg:code.message,showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
        }
      },
      error : function() {
        alert('error');
      }
    });
    return code1
  }

  function addActivity(){
    var row = $('#dg').datagrid('getSelected');
    if (updData(row.activityId)==200){
      $('#test').window('close');
    }
  }

  function updData(s){
    var code1 = 0;
    $.ajax({
      method : 'GET',
      url : 'rest/page/activityM/upd?manageId=${user.teacherid}&activityId='+s+'',
      async : false,
      dataType : 'json',
      success : function(code) {
        code1 = code.code
        if(code.code == 200){
          $.messager.show({title:'操作提示',msg:code.message+"请点击表单下刷新按钮刷新显示",showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
        }else{
          $.messager.show({title:'操作提示',msg:code.message,showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
        }
      },
      error : function() {
        alert('error');
      }
    });
    return code1
  }

  function getData(r,p,s){
    var infor_data = [];
    var total = 0;
    $.ajax({
      method : 'post',
      url : 'rest/page/activityM/selects',
      data:'startrow='+r+'&pageSize='+p+'&activityTitle='+s+'&manageId=${user.teacherid}',
      async : false,
      dataType : 'json',
      success : function(data) {
        infor_data = data.data
        total = data.total
      },
      error : function() {
        alert('error');
      }

    });
    var rows = [];
    if(infor_data!=null) {
      for (var i = 0; i < infor_data.length; i++) {
        rows.push({
          total: total,
          wh: s,
          activityId: infor_data[i].activityId,
          activityTitle: infor_data[i].activityTitle,
          activityCollege: infor_data[i].activityCollege,
          activityLocation: infor_data[i].activityLocation,
          activityTime: infor_data[i].activityTime,
          functionAttendance: infor_data[i].functionAttendance,
          activityPictureUrl: infor_data[i].activityPictureUrl,
          activityType: infor_data[i].activityType
        });
      }
    }
    return rows;
  }

  function doSearch(value){
    i = 1;
    $('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData', getData(0,10,value));
  }
</script>
</body>
</html>
